package com.lhy.wallet.controller;

import com.lhy.wallet.common.ApiRestResponse;
import com.lhy.wallet.exception.MalletException;
import com.lhy.wallet.pojo.User;
import com.lhy.wallet.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: 卢辉宇
 * @date: 2023/3/10 16:27
 * @description:
 */
@RestController
public class UserController {
    @Resource
    UserService userService;

    /**
     * 查询余额接口
     * @param userId
     * @return
     */
    @PostMapping("/user/selectRemainder")
    public ApiRestResponse selectRemainder(Integer userId) throws MalletException {
        User user = userService.selectRemainder(userId);
        return ApiRestResponse.seccess(user);
    }

    /**
     * 消费接口
     * @param userId
     * @param amount 消费金额
     * @return
     */
    @PostMapping("/user/consume")
    public ApiRestResponse consume(Integer userId,Double amount) throws MalletException {
        userService.consume(userId,amount);
        return ApiRestResponse.seccess();
    }

    /**
     * 退款接口
     * @param userId
     * @param billId
     * @param amount
     * @return
     */
    @PostMapping("/user/refund")
    public ApiRestResponse refund(Integer userId,String billId,Double amount) throws MalletException {
        userService.refund(userId,billId,amount);
        return ApiRestResponse.seccess();
    }
}
